<?php

namespace App\Models;

use App\Traits\ModelDate;
use Illuminate\Support\Facades\DB;
use Spatie\Permission\Traits\HasRoles;
use Laravel\Passport\HasApiTokens;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class AdminUserModel extends Authenticatable
{

    use HasRoles, HasApiTokens, Notifiable, HasFactory;
    use ModelDate;

    //use SoftDeletes;
    /**
     * @var string
     */
    protected $table = 'sys_admin_user';

    protected $primaryKey = 'id';

    public $incrementing = true;

    protected $guarded = [];

    const UPDATED_AT = null; //更新不需要这个字段可以设置为null

    const CREATED_AT = null; //更新不需要这个字段可以设置为null

    //用户城市
    public static function queryUserCityList()
    {
        $query = DB::table('sys_admin_user_city as auc')
            ->leftJoin('china as pc', 'auc.provinceId', '=', 'pc.id')
            ->leftJoin('china as cc', 'auc.cityId', '=', 'cc.id')
            ->leftJoin('china as ac', 'auc.areaId', '=', 'ac.id');
        return $query;
    }

    //用户部门
    public static function queryUserDeptList()
    {
        $query = DB::table('sys_admin_user_dept as aud')
            ->leftJoin('sys_admin_dept as ad', 'aud.deptId', '=', 'ad.id');
        return $query;
    }

    //用户角色
    public static function queryUserRoleList()
    {
        $query = DB::table('sys_admin_user_role as aur')
            ->leftJoin('sys_admin_role as ar', 'aur.roleId', '=', 'ar.id');
        return $query;
    }


}
